local getmetatable = getmetatable
local setmetatable = setmetatable
local module = module
local require = require
local type = type
local error = error
local tonumber = tonumber
local print = print

module('eg.ArithmeticFixture')
_VERSION='0.1'

local PrimitiveFixture = require('fit.PrimitiveFixture')

local function doRows(self, rows)
    -- TODO: How best to call the parent class's doRows?
    -- super.doRows(rows.more) -- skip column heads
    self.parent.doRows(self, rows.more)
end

local function doCell(self, cell, column)
    if column == 1 then
        self.x = self.parseNum(cell)
    elseif column == 2 then
        self.y = self.parseNum(cell)
    elseif column == 3 then
        self:check(cell, self.x + self.y)
    elseif column == 4 then
        self:check(cell, self.x - self.y)
    elseif column == 5 then
        self:check(cell, self.x * self.y)
    elseif column == 6 then
        self:check(cell, self.x / self.y)
    else
        self:ignore(cell)
    end
end

function __call()
    local aArithmeticFixture = PrimitiveFixture()

    -- We need access to the parent's doRows function
    aArithmeticFixture.parent = {}
    aArithmeticFixture.parent.doRows = aArithmeticFixture.doRows

    aArithmeticFixture.x = 0
    aArithmeticFixture.y = 0
    aArithmeticFixture.doRows = doRows
    aArithmeticFixture.doCell = doCell

    return aArithmeticFixture
end

setmetatable(_M, _M)
